package com.guige;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.support.SpringBootServletInitializer;

import javax.annotation.PostConstruct;

@Slf4j
@SpringBootApplication
@EnableConfigurationProperties
public class ConvertApplication extends SpringBootServletInitializer implements CommandLineRunner {
	@Value("${guige.http.proxy.ip:}")
	String proxyHost;

	@Value("${guige.http.proxy.port:}")
	String proxyPort;
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(ConvertApplication.class);
	}
	public static void main(String[] args) {
		SpringApplication.run(ConvertApplication.class, args);
	}

	@Override
	public void run(String... strings) throws Exception {
		log.info("parservaluation start OK");
	}
	@PostConstruct
	protected void setupHttpProxy() {
		log.info("=================================");
		log.info("server start.");
		log.info("proxy ip:" + this.proxyHost + " port:" + this.proxyPort);
		log.info("=================================");

		if (StringUtils.isNotBlank(this.proxyHost) || StringUtils.isNotBlank(this.proxyPort)) {
			System.setProperty("http.proxyHost", this.proxyHost);
			System.setProperty("http.proxyPort", this.proxyPort);
		}
	}
}
